﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Skynet
{
    public partial class NodeEditorNV : Form
    {
        public IconNode b;
        public frmSkynet pf;

        public NodeEditorNV()
        {
            InitializeComponent();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            
            if (cmbSyn.SelectedItem != null)
            {
                var d = (from word in pf.words.wordList
                         where (word.Row.Cells[0].Value.ToString() == cmbSyn.SelectedItem.ToString())
                         select word).FirstOrDefault();
                b.word = d.Row.Cells[0].Value.ToString();
                b.Label = d.Row.Cells[0].Value.ToString();
            }
            else
            {
                if (cmbSyn.Text.Trim() != "")
                {
                    var word = new Word();
                    var row = new DataGridViewRow();
                    row.Cells.Add(new DataGridViewTextBoxCell());
                    row.Cells[0].Value = cmbSyn.Text;
                    word.Row = row;
                    this.pf.words.wordList.Add(word);
                    b.word = cmbSyn.Text.Trim();
                    b.Label = cmbSyn.Text.Trim();
                }
            }
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void NodeEditorNV_Load(object sender, EventArgs e)
        {
            b = (IconNode)(this.Tag);
            pf = (frmSkynet)Application.OpenForms[0];
            cmbSyn.Items.Clear();
            foreach (Word word in pf.words.wordList)
            {
                cmbSyn.Items.Add(word.Row.Cells[0].Value.ToString());
            }
            if (b.word != null) cmbSyn.SelectedItem = b.word;
        }
    }
}
